package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.PmsProductAttributeMapper;
import com.mall.model.domain.PmsProductAttribute;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【pms_product_attribute(商品属性参数表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class PmsProductAttributeApiImpl extends ServiceImpl<PmsProductAttributeMapper, PmsProductAttribute>
        implements PmsProductAttributeApi {

    @Autowired
    private PmsProductAttributeMapper attributeMapper;

    @Override
    public Page<PmsProductAttribute> findByAttributeCategoryPage(Long id, Integer type, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<PmsProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductAttribute::getProductAttributeCategoryId,id)
                .eq(type!=null,PmsProductAttribute::getType,type);
        Page<PmsProductAttribute> page = new Page<>(pageNum, pageSize);
        Page<PmsProductAttribute> attributeList = attributeMapper.selectPage(page,queryWrapper);
        return attributeList;
    }



    @Override
    public void addAttribute(PmsProductAttribute attribute) {
        attributeMapper.insert(attribute);
    }

    @Override
    public List<PmsProductAttribute> findByIds(List<Long> attributeIds) {
        LambdaQueryWrapper<PmsProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(PmsProductAttribute::getId,attributeIds);
        List<PmsProductAttribute> attributeList = attributeMapper.selectList(queryWrapper);
        return attributeList;
    }

    @Override
    public PmsProductAttribute findById(Long productAttributeId) {
        return attributeMapper.selectById(productAttributeId);
    }

    @Override
    public void deleteByIds(Long[] ids) {
        attributeMapper.deleteBatchIds(Arrays.asList(ids));
    }




    @Override
    public void updateAttribute(PmsProductAttribute attribute) {
        attributeMapper.updateById(attribute);
    }

    @Override
    public List<PmsProductAttribute> findByAttributeCategoryIds(List<Long> attributeCategoryIds) {
        LambdaQueryWrapper<PmsProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductAttribute::getProductAttributeCategoryId,attributeCategoryIds);

        List<PmsProductAttribute> attributeList = attributeMapper.selectList(queryWrapper);
        return attributeList;
    }

    @Override
    public List<PmsProductAttribute> findByAttributeCategoryId(Long id) {
        LambdaQueryWrapper<PmsProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductAttribute::getProductAttributeCategoryId,id);
        List<PmsProductAttribute> attributeList = attributeMapper.selectList(queryWrapper);
        return attributeList;
    }

}




